package dao;
import java.sql.*;
import java.util.*;
import pojo.Room;

public class RoomDao {
	
	private Connection con;

	
	public RoomDao()
	{
		try{
			
			con=DBPool.getConnection();
			
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		
	}
	public Vector<String> getAllRooms()
	{
		 
		Vector<String> roomlist=new Vector<String>();
		String sql="select * from room";
	//	Room room=null;
		try{
			Statement smt=con.createStatement();
			ResultSet rs=smt.executeQuery(sql);
			
			while(rs.next())
			{
				//room.setRoomid(rs.getInt(1));
				//room.setRoomname(rs.getString(2));
				roomlist.add(rs.getString(2));
			}
			rs.close();
			smt.close();
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		
		return roomlist;
	}
	
	/*public Room getRoom(String roomname)
	{
		Room r=new Room();
		String sql="select * from room where roomname="+"'"+roomname+"'";
		try{
			Statement smt=con.createStatement();
			ResultSet rs=smt.executeQuery(sql);
			rs.next();
			r.setRoomid(rs.getInt(1));
			r.setRoomname(rs.getString(2));
			rs.close();
			smt.close();
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		
		return r;
	}*/
	public int getRoomId(String roomname)
	{
		int roomid=0;
		String sql="select * from room where roomname="+"'"+roomname+"'";
		try{
			Statement smt=con.createStatement();
			ResultSet rs=smt.executeQuery(sql);
			rs.next();
			roomid=rs.getInt(1);
			rs.close();
			smt.close();
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		
		return roomid;
	}
	public int createRoom(String roomname)
	{
		int roomid=0;
		String sql="insert into room (roomname)values('"+roomname+"')";
		try{
			Statement smt=con.createStatement();
			roomid=smt.executeUpdate(sql);
			smt.close();
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return roomid;
	}
}
